<template>
	<view>
		<view class="home-tomato-wrapper" v-for="(item,index) in tomato" :key='index'>
			<view class="home-tomato-title">
				<image src="../static/tomato.png" class='title-icon' @click="startClock(item.time)" />
				<view class="home-tomato-content" @click="startClock(item.time)">{{item.note}}</view>
				<view class="iconfont" @click="delTomato(index)">&#xec45;</view>
			</view>
			<view class="home-tomato-clock" @click="startClock(item.time)">
				<view class="iconfont">&#xe660;</view>
				<view class="time">{{item.time}}</view>
			</view>
		</view>
		<CountDown :clock.sync='clock' v-show='show' :show.sync='show' />
	</view>
</template>

<script>
	import CountDown from './CountDown.vue'
	export default {
		data() {
			return {
				tomatoIcon: 'tomato-icon',
				clock: '',
				show: false,
				index: ''
			}
		},
		created() {
			this.$store.commit('getTomato')
		},
		computed: {
			tomato() {
				return this.$store.state.tomatoData.tomato
			}
		},
		components: {
			CountDown
		},
		methods: {
			startClock(time) {
				this.show = true;
				this.clock = time;
			},
			delTomato(index) {
				this.index = index
				this.$store.commit('delTomato', this.index)
				uni.showToast({
					title: '删除成功'
				})
				this.index = ''
			}
		}
	}
</script>

<style lang='scss'>
	.home-tomato-wrapper {
		box-shadow: 1px 1px 2px 2px rgb(201, 199, 199);
		border-radius: 5px;
		border: 1px solid white;
		padding: 5px;
		margin: 15px;

		>.home-tomato-title {
			display: flex;
			padding: 2px 5px;
			justify-content: center;
			align-items: center;
			border-bottom: 1px solid #d6d4d4;
			height: 40px;
			overflow: auto;

			>.title-icon {
				width: 30px;
				height: 30px;
				flex-shrink: 0;
			}

			>.home-tomato-content {
				flex-grow: 1;
				margin-left: 20px;
				white-space: nowrap;
				overflow: auto;
			}
		}

		>.home-tomato-clock {
			display: flex;
			justify-content: center;
			font-size: 20px;
			align-items: center;
			margin-top: 10px;

			>.time {
				color: #7d8bae;
				margin-left: 10px;
				font-weight: 600;
			}
		}
	}
</style>
